﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zadatak3
{
    public interface SignalListener
    {
        //Moj tekst
        /// <summary>
        /// Termostat okida ovaj event.
        /// </summary>
        /// <param name="highlow">
        /// true: signal postavljen visoko - temperatura je niza od granicne, 
        /// false: signal postavljen nisko - temperatur je visa od granicne
        /// </param>
        void OnSignal(bool highlow);
    }

    public interface Senzor
    {
        /// <summary>
        /// Vraca trenutnu temperaturu.
        /// </summary>
        /// <returns></returns>
        double DohvatiTrenutnuTemperaturu();
    }

    /// <summary>
    /// Termostat cita trenutnu temperaturu preko Senzora i okida high/low signal ovisno o tome
    /// da li je trenutna temperatura veca/jednaka ili manje od granicne.
    /// </summary>
    public class Termostat
    {
        private SignalListener signalListener;
        private Senzor senzor;

        public double GranicnaTemperatura { get; set; }

        public Termostat(SignalListener signalListener, Senzor senzor)
        {
            this.signalListener = signalListener;
            this.senzor = senzor;
            this.GranicnaTemperatura = 22.0;
        }

        public void provjeri()
        {
            double trenutnaTemperatura = senzor.DohvatiTrenutnuTemperaturu();
            
            if (trenutnaTemperatura < GranicnaTemperatura)
            {
                signalListener.OnSignal(true);
            }
            else
            {
                signalListener.OnSignal(false);
            }
        }
    }
}
